package com.hardydou.framework.websocket;

import java.nio.ByteBuffer;
import java.util.Date;

/**
 * @author ：hardy
 * @description：WebSocket消息对象
 * @date ：Created in 2020/7/2
 * @Copyright ：Hardydou.com
 */
public class WsMessage {

    /***
     * 消息来源
     */
    private Long fromUserId;

    /***
     * 接收方
     */
    private Long toUserId;
    /***
     * 消息类型
     */
    private WsMessageType type;
    /***
     * 文本内容
     */
    private String textData;
    /***
     * 二进制数据内容
     */
    private ByteBuffer byteData;

    private Date time;

    public boolean isText() {
        return type.equals(WsMessageType.TXT);
    }

    public boolean isByte() {
        return type.equals(WsMessageType.BYTE);
    }

    public Long getFromUserId() {
        return fromUserId;
    }

    public void setFromUserId(Long fromUserId) {
        this.fromUserId = fromUserId;
    }

    public Long getToUserId() {
        return toUserId;
    }

    public void setToUserId(Long toUserId) {
        this.toUserId = toUserId;
    }

    public WsMessageType getType() {
        return type;
    }

    public void setType(WsMessageType type) {
        this.type = type;
    }

    public String getTextData() {
        return textData;
    }

    public void setTextData(String textData) {
        this.textData = textData;
    }

    public ByteBuffer getByteData() {
        return byteData;
    }

    public void setByteData(ByteBuffer byteData) {
        this.byteData = byteData;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    public static enum WsMessageType {
        TXT, BYTE
    }
}
